package com.github.lee.unsplash.ui.splash

import androidx.activity.viewModels
import androidx.databinding.ViewDataBinding
import com.github.lee.mvvm.core.ui.BaseActivity
import com.github.lee.unsplash.BuildConfig
import com.github.lee.unsplash.ui.main.MainActivity

class SplashActivity : BaseActivity<ViewDataBinding, SplashVM>() {

    override fun onCreateViewModel(): SplashVM =
        viewModels<SplashVM>().value


    override fun onObserveData() {
        super.onObserveData()
        pageVM.apply {
            timerLiveData.observe(this@SplashActivity) {
                if (it <= 0) {
                    handlerTimeOut()
                }
            }
        }
    }

    override fun onSetViewData() {
        super.onSetViewData()
        translucentStatusBar()
    }

    override fun onBackPressed() {
        if (BuildConfig.DEBUG) {
            handlerTimeOut()
        }
    }

    //===Desc:=========================================================

    private fun handlerTimeOut() {
        MainActivity.start(mContext, 0)
        finish()
    }

}